PEAR/ObjectOperatorIndent: improve end of statement detection when getting the next object operator #1158
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR fixes a bug where
PEAR.WhiteSpace.ObjectOperatorIndent
would generate a false positive when checking multiple chained object operators in a multidimensional array.The problem is that the code was using the
$local
parameter offindNext()
to limit the scope of the search when reassigning$next
to the next object operator, and$local
only considers a semicolon as the end of a statement.Different chained calls are not necessarily separated by a semicolon (as shown in the test added in this commit). This means that the sniff currently considers the object operators on the second and third chained method calls as part of the first chained method call and checks their indentation using the indentation of the first element on the first chained call as its base.
To fix this problem, instead of relying on the
$local
parameter to find the end of the statement, the end of the statement as defined byFile::findEndOfStatement()
is now used.See #1154 for more details on the problem.
Suggested changelog entry
Fixed: false positive when
PEAR.WhiteSpaceObjectOperatorIndent
checks multiple chained method calls in a multidimensional arrayRelated issues/external references
Fixes #1154
Fixes squizlabs/PHP_CodeSniffer#3718
Types of changes
PR checklist